import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
export const useCounterStore = defineStore('counter', () => {
    // const count = ref(0)
    // const doubleCount = computed(() => count.value * 2)
    // function increment() {
    //   count.value++
    // }
    const username = ref('')
    const cartList = ref([])
    const saveUsername = (name) => {
        username.value = name
    }
    const addItem = (payload) => {
        const index = cartList.value.findIndex(item => item.id == payload.id)
        if (index > -1) {
            cartList.value.length = 0
        } else {
            cartList.value.push({
                ...payload,
                count: 1,
                checked: false
            })
        }
    }

    const totalCount = computed(item => {
        let res = 0
        cartList.value.forEach(item => item.id == id)


    })
    return { username, cartList, saveUsername, addItem }
})